package generators;

import gamebackend.Block;

import java.util.Random;

public class SquareGenerator extends AbstractRandomGenerator implements BlockGenerator {

	
	public SquareGenerator(final Block the_block, Random the_random, double the_chance) {
		super(the_block, the_random, the_chance);
	}
	@Override
	public void generate(Block[][] blocks) {
		for (int col = 0; col < blocks[0].length - 1; col++) {
			if (getRandom().nextDouble() < getChance()) {
				if (blocks[1][col] == Block.EMPTY_BLOCK &&
						blocks[1][col + 1] == Block.EMPTY_BLOCK &&
						blocks[2][col] == Block.EMPTY_BLOCK &&
						blocks[2][col + 1] == Block.EMPTY_BLOCK) {
					blocks[1][col] = getBlock();
					blocks[1][col + 1] = getBlock();
					blocks[2][col] = getBlock();
					blocks[2][col + 1] = getBlock();
				}
			}
		}
		
	}

}
